<!-- 天津官网——查询记录 -->
<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="5">
					<a-form-item label="身份证号" name="accuserIdCard">
						<a-input
							v-model:value="searchFormState.accuserIdCard"
							placeholder="请输入身份证号"
							enter-button
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="5">
					<a-form-item label="手机号" name="mobile">
						<a-input
							v-model:value="searchFormState.mobile"
							placeholder="请输入手机号"
							enter-button
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="回传时间">
						<a-range-picker
							v-model:value="createTimeArr"
							@change="dateChange"
							:default-value="[dayjs('2024-11-11', 'YYYY-MM-DD'), dayjs('2024-11-15', 'YYYY-MM-DD')]"
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false" class="mt-2">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
		>
			<template #operator>
				<a-space>
					<a-button type="primary" @click="exportExcel">
						<download-outlined/>
						导出
					</a-button>
				</a-space>
			</template>
		</s-table>
	</a-card>
</template>

<script setup name="websiteRecord">
import websiteRecordApi from "@/api/tjzy/website/record/websiteRecordApi";
import dayjs from "dayjs";
import downloadUtil from "@/utils/downloadUtil";

const searchFormState = ref({
	current: 1,
	size: 10,
	accuserIdCard: undefined,
	mobile: undefined,
	beginTime: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
	endTime: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
})
const searchFormRef = ref()
const tableRef = ref()
const createTimeArr = ref([dayjs().startOf('day'), dayjs().endOf('day')])
const columns = [
	{
		title: '身份证号码',
		dataIndex: 'accuserIdCard'
	},
	{
		title: '手机号',
		dataIndex: 'mobile'
	},
	{
		title: '渠道',
		dataIndex: 'channel'
	},
	{
		title: 'IP地址',
		dataIndex: 'ip',
		ellipsis: true
	},
	{
		title: '创建时间',
		dataIndex: 'createTime'
	}
]
const dateChange = (value) => {
	searchFormState.value.beginTime = value[0].format('YYYY-MM-DD').concat(' 00:00:00')
	searchFormState.value.endTime = value[1].format('YYYY-MM-DD').concat(' 23:59:59')
}
const loadData = (parameter) => {
	searchFormState.value.current = parameter.current
	searchFormState.value.size = parameter.size
	return websiteRecordApi.pageList(searchFormState.value).then((res) => {
		return res
	})
}
const exportExcel = () => {
	websiteRecordApi.export(searchFormState.value).then((res) => {
		downloadUtil.resultDownload(res)
	})
}
// 重置
const reset = () => {
	searchFormRef.value.resetFields()
	createTimeArr.value = [dayjs().startOf('day'), dayjs().endOf('day')]
	tableRef.value.refresh(true)
}
</script>
